home *** CD-ROM | disk | FTP | other *** search
- Path: news.ucdavis.edu!quad!knight
- From: knight@quad.cs.ucdavis.edu (James Knight)
- Newsgroups: comp.lang.c
- Subject: Re: What is wrong with this loop?
- Date: 19 Apr 1996 22:43:02 GMT
- Organization: University of California, Davis
- Message-ID: <4l94tm$ft7@mark.ucdavis.edu>
- References: <4l86la$1t9@uwm.edu> <4l8apa$kv8@spanky.pls.ov.com>
- NNTP-Posting-Host: quad.cs.ucdavis.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- Fletcher.Glenn@ov.com (glenn@ov.com) wrote:
- : In article 1t9@uwm.edu, mardavuy@alpha2.csd.uwm.edu (Mario David Uy) writes:
- : >
- : > scanf("%c", &cd);
- : > while (cd != 'm' || cd ! 'f' || cd != 'o')
- : > {
- : > printf("Re-enter m, f, or o.\n");
- : > scanf(%c", &cd);
- : > }
- : > ...
- : >}
- : >
-
- : My bet is that you have forgotten that the '\n' in your input is
- : also a character. Try changing your while statement from:
-
- : while (cd != 'm' || cd ! 'f' || cd != 'o')
-
- : to: while(cd != 'm' || cd != 'f' || cd != 'o' || cd != '\n')
-
- Actually, that won't work, because the loop should be
-
- while (ch != 'm' && cd != 'f' && cd != 'o')
-
- The original version will match every character. And adding the
- "cd != '\n'" clause to that won't help.
-
- The scanf solution posted in the other replies is what is
- required (adding a space after the %c).
-
- Jim
-
-